import tkinter as tk
def sub():
    tianGan_list=["甲","乙","丙","丁","戊","己","庚","辛","壬","癸"] #天干列表
    diZhi_list=["子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"] #地支列表
    shengXiao_list=["鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"] #生肖列表

    inputYear = txt1.get()
    inputYear=int(inputYear)
    for i in range(inputYear,inputYear+12):
        a = (i + 6)%10  #天干计算
        b = (i + 8)%12  #地支、生肖计算
        c1 = tianGan_list[a]
        c2 = diZhi_list[b]
        c3 = shengXiao_list[b]
        #print("{}年   {}{}     {}".format(i,c1,c2,c3))
        #列表框输出
        listbox1.insert(tk.END,"{}年   {}{}     {}".format(i,c1,c2,c3))

#建立窗口
win =tk.Tk()
win.title('天干地支')
win.geometry("240x280") #默认窗口大小
#建立组件
lb1 = tk.Label(win,text = '输入年份')
txt1 = tk.Entry(win,width=10,justify='center')
listbox1 = tk.Listbox(win,height=13)
listbox1.insert(0,' 年份  天干地支  生肖')
cmd = tk.Button(win, text = '天干地支与生肖', command = sub)
#组件布局
lb1.grid(row=0, column=0)
txt1.grid(row=1,column=0)
cmd.grid(row=2,column=0)
listbox1.grid(row=0,column=1,rowspan=3)
#接收窗口事件
win.mainloop()
